﻿using Nop.Admin.Models.Common;
using Nop.Admin.Models.XJ;
using Nop.Core;
using Nop.Core.Domain.XJ;
using Nop.Services.Catalog;
using Nop.Services.Common;
using Nop.Services.Customers;
using Nop.Services.Directory;
using Nop.Services.Logging;
using Nop.Services.Media;
using Nop.Services.Security;
using Nop.Services.XJ;
using Nop.Web.Framework.Controllers;
using Nop.Web.Framework.Kendoui;
using Nop.Web.Framework.Mvc;
using System;
using System.Linq;
using System.Web.Mvc;

namespace Nop.Admin.Controllers
{
	public class EquipmentController : BaseAdminController
	{
		#region Fields
		private readonly IPermissionService _permissionService;
		private readonly IPictureService _pictureService;
		private readonly IWorkContext _workContext;
		private readonly IOrganizationService _organizationServce;
		private readonly IDepartmentService _departmentServce;
		private readonly ICustomerService _customerService;
		private readonly IGenericAttributeService _genericAttributeService;
		private readonly IXJPlaceService _xjPlaceService;
		private readonly IXJEquipmentCategoryService _xJEquipmentCategoryService;
		private readonly IXJEquipmentService _xJEquipmentService;
		private readonly IXJEquipmentStockService _xJEquipmentStockService;
		private readonly IXJInspectionService _xJInspectionService;
		private readonly IXJInspectionPlanService _xJInspectionPlanService;
		private readonly IXJMaintenanceService _xJMaintenanceService;
		private readonly IXJMaintenanceCommentService _xJMaintenanceCommentService;
		private readonly ICustomerActivityService _customerActivityService;
		private readonly ILogger _logger;
		#endregion

		#region Constructors
		public EquipmentController(IPermissionService permissionService,
			IPictureService pictureService,
			IWorkContext workContext,
			IOrganizationService organizationServce,
			IDepartmentService departmentServce,
			ICustomerService customerService,
			IGenericAttributeService genericAttributeService,
			IXJPlaceService xjPlaceService,
			IXJEquipmentCategoryService xJEquipmentCategoryService,
			IXJEquipmentService xJEquipmentService,
			IXJEquipmentStockService xJEquipmentStockService,
			IXJInspectionService xJInspectionService,
			IXJInspectionPlanService xJInspectionPlanService,
			IXJMaintenanceService xJMaintenanceService,
			IXJMaintenanceCommentService xJMaintenanceCommentService,
			ICustomerActivityService customerActivityService,
			ILogger logger)
		{
			this._permissionService = permissionService;
			this._pictureService = pictureService;
			this._workContext = workContext;
			this._organizationServce = organizationServce;
			this._departmentServce = departmentServce;
			this._customerService = customerService;
			this._genericAttributeService = genericAttributeService;
			this._xjPlaceService = xjPlaceService;
			this._xJEquipmentCategoryService = xJEquipmentCategoryService;
			this._xJEquipmentService = xJEquipmentService;
			this._xJEquipmentStockService = xJEquipmentStockService;
			this._xJInspectionService = xJInspectionService;
			this._xJInspectionPlanService = xJInspectionPlanService;
			this._xJMaintenanceService = xJMaintenanceService;
			this._xJMaintenanceCommentService = xJMaintenanceCommentService;
			this._customerActivityService = customerActivityService;
			this._logger = logger;
		}
		#endregion

		#region Utilities

		[NonAction]
		protected virtual void PrepareAllCategoriesModel(EquipmentModel model)
		{
			if (model == null)
				throw new ArgumentNullException("model");

			Type enumType = typeof(CategoryMainEnum);
			Enum.GetNames(enumType).ToList().ForEach(s =>
			{
				string value = Enum.Format(enumType, Enum.Parse(enumType, s), "d");
				model.AvailableTypes.Add(new SelectListItem { Text = s, Value = value });
			});

			model.AvailableCategories.Add(new SelectMenuModel
			{
				name = "请选择",
				id = 0,
				open = true,
			});
			var categorys = _xJEquipmentCategoryService.GetAllCategorys(isConsumables: false, showHidden: false);
			foreach (var c in categorys)
				model.AvailableCategories.Add(new SelectMenuModel { name = c.Name, id = c.Id, pId = c.PId });

			model.AvailableEquipments.Add(new SelectListItem
			{
				Text = "请选择",
				Value = "0"
			});
			var equipments = _xJEquipmentService.GetAllEquipments(showHidden: false);
			foreach (var c in equipments)
				model.AvailableEquipments.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString() });

			var places = _xjPlaceService.GetAllPlaces(showHidden: false);
			foreach (var p in places)
				model.AvailablePlaces.Add(new SelectListItem { Text = p.Name, Value = p.Id.ToString() });

			model.AvailableDepartments.Add(new SelectListItem
			{
				Text = "请选择",
				Value = "0"
			});
			var departments = _departmentServce.GetAllDepartments(pid: 0, showHidden: false);
			foreach (var d in departments)
				model.AvailableDepartments.Add(new SelectListItem { Text = d.Name, Value = d.Id.ToString() });
		}
		#endregion

		#region List
		public ActionResult Index()
		{
			return RedirectToAction("List");
		}

		public virtual ActionResult List()
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var model = new EquipmentListModel();

			//model.AvailableTypes.Add(new SelectListItem
			//{
			//	Text = "全部",
			//	Value = "0"
			//});
			//Type enumType = typeof(CategoryMainEnum);
			//Enum.GetNames(enumType).ToList().ForEach(s =>
			//{
			//	string value = Enum.Format(enumType, Enum.Parse(enumType, s), "d");
			//	model.AvailableTypes.Add(new SelectListItem { Text = s, Value = value });
			//});
			model.AvailableCategories.Add(new SelectMenuModel
			{
				name = "全部",
				id = 0,
				open = true,
			});
			var categorys = _xJEquipmentCategoryService.GetAllCategorys(isConsumables: false, showHidden: false);
			foreach (var c in categorys)
				model.AvailableCategories.Add(new SelectMenuModel { name = c.Name, id = c.Id, pId = c.PId });
			model.AvailablePlaces.Add(new SelectListItem
			{
				Text = "全部",
				Value = "0"
			});
			var places = _xjPlaceService.GetAllPlaces(showHidden: false);
			foreach (var p in places)
				model.AvailablePlaces.Add(new SelectListItem { Text = p.Name, Value = p.Id.ToString() });

			//model.AvailableDepartments.Add(new SelectListItem
			//{
			//	Text = "全部",
			//	Value = "0"
			//});
			//var departments = _departmentServce.GetAllDepartments(pid: 0, showHidden: false);
			//foreach (var d in departments)
			//	model.AvailableDepartments.Add(new SelectListItem { Text = d.Name, Value = d.Id.ToString() });

			return View(model);
		}

		[HttpPost]
		public virtual ActionResult List(DataSourceRequest command, EquipmentListModel model)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedKendoGridJson();

			var categories = _xJEquipmentService.GetAllEquipments(
				categoryId: model.SearchCategoryId,
				placeId: model.SearchPlaceId,
				pId: model.SearchPId,
				name: model.SearchName,
				pp: model.SearchManufacturer,
				gg: model.SearchSpecification,
				isConsumables: false,
				onlyStock: model.OnlyStock,
				onlyWarn: model.OnlyWarn,
				pageIndex: command.Page - 1,
				pageSize: command.PageSize);
			var gridModel = new DataSourceResult
			{
				Data = categories.Select(x =>
				{
					x.CategoryMainName = Enum.GetName(typeof(CategoryMainEnum), x.CategoryMainId);
					//x.Breadcrumb = x.GetFormattedBreadCrumb(_xJEquipmentService);
					return x;
				}),
				Total = categories.TotalCount
			};
			return Json(gridModel);
		}
		#endregion

		#region Delete

		[HttpPost]
		public virtual ActionResult Delete(int id)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var equipment = _xJEquipmentService.GetXJEquipmentById(id);
			if (equipment == null)
				//No equipment found with the specified id
				return RedirectToAction("List");

			try
			{
				_xJEquipmentService.DeleteEquipment(equipment);

				//activity log
				_customerActivityService.InsertActivity("DeleteEquipment", "删除设施设备：{0}", equipment.Name);

				SuccessNotification("删除成功");
			}
			catch (Exception ex)
			{
				ErrorNotification(ex.Message);

				return RedirectToAction("Edit", new { id });
			}
			return RedirectToAction("List");
		}

		[HttpPost]
		public virtual ActionResult EquipmentDelete(int id)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var equipment = _xJEquipmentService.GetXJEquipmentById(id);
			if (equipment == null)
				return Json(new { result = false, msg = "不能删除" });

			try
			{
				if (equipment.UseIn > 0)
					return Json(new { result = false, msg = "使用中数量未处理，不能删除" });
				_xJEquipmentService.DeleteEquipment(equipment);

				var children = _xJEquipmentService.GetAllEquipments(pId: equipment.Id);
				if (children.Any())
					return Json(new { result = false, msg = "子节点未处理，不能删除" });

				//activity log
				_customerActivityService.InsertActivity("DeleteEquipment", "删除设施设备：{0}", equipment.Name);

				return Json(new { result = true, msg = "删除成功" });
			}
			catch (Exception ex)
			{
				return Json(new { result = false, msg = ex.Message });
			}
			//return new NullJsonResult();
		}

		#endregion

		#region Equipments

		[HttpPost]
		public virtual ActionResult EquipmentList(DataSourceRequest command, int pId)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedKendoGridJson();

			var equipments = _xJEquipmentService.GetAllEquipments(
				pId: pId,
				showHidden: false,
				pageIndex: command.Page - 1,
				pageSize: command.PageSize);
			var gridModel = new DataSourceResult
			{
				Data = equipments.Select(x =>
				{
					var categoryModel = new EquipmentModel
					{
						Id = x.Id,
						CategoryMainId = x.CategoryMainId,
						PId = x.PId,
						Name = x.Name,
						DisplayOrder = x.DisplayOrder,
						Published = x.Published,
						Breadcrumb = x.GetFormattedBreadCrumb(_xJEquipmentService)
					};
					return categoryModel;
				}),
				Total = equipments.TotalCount
			};

			return Json(gridModel);
		}

		public virtual ActionResult EquipmentUpdate(EquipmentModel model)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var equipment = _xJEquipmentService.GetXJEquipmentById(model.Id);
			if (equipment == null)
				throw new ArgumentException("No equipment mapping found with the specified id");

			equipment.DisplayOrder = model.DisplayOrder;
			_xJEquipmentService.UpdateXJEquipment(equipment);

			return new NullJsonResult();
		}

		public virtual ActionResult AddPopup(int pId = 0, int cId = 0)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var model = new EquipmentModel
			{
				CategoryMainId = (int)CategoryMainEnum.设施设备,
				Published = true,
			};
			if (pId > 0)
			{
				var equipment = _xJEquipmentService.GetXJEquipmentById(pId);
				if (null != equipment)
				{
					model.CategoryMainId = (int)CategoryMainEnum.配件;
					model.CategoryId = equipment.CategoryId;
					model.CategoryName = _xJEquipmentCategoryService.GetNameById(equipment.CategoryId);
					model.PId = pId;
					//model.MeanLife = equipment.MeanLife;
					//model.Manufacturer = equipment.Manufacturer;
					//model.Specification = equipment.Specification;
					//model.Version = equipment.Version;
					if (equipment.Places.Any())
					{
						model.PlaceIds = equipment.Places.Select(x => x.Id).ToList();
						model.PlaceNames = string.Join(",", equipment.Places.Select(x => x.Name));
					}
				}
			}
			else if (cId > 0)
			{
				model.CategoryMainId = (int)CategoryMainEnum.设施设备;
				model.CategoryId = cId;
			}
			//categories
			PrepareAllCategoriesModel(model);
			return View(model);
		}

		public virtual ActionResult EditPopup(int id)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var model = new EquipmentModel();
			var equipment = _xJEquipmentService.GetXJEquipmentById(id);
			if (null != equipment)
			{
				model.Id = equipment.Id;
				model.CategoryMainId = equipment.CategoryMainId;
				model.CategoryId = equipment.CategoryId;
				model.CategoryName = _xJEquipmentCategoryService.GetNameById(equipment.CategoryId);
				model.PId = equipment.PId;
				model.Name = equipment.Name;
				model.Price = equipment.Price;
				model.MeanLife = equipment.MeanLife;
				model.Manufacturer = equipment.Manufacturer;
				model.Specification = equipment.Specification;
				model.Unit = equipment.Unit;
				model.DisplayOrder = equipment.DisplayOrder;
				model.StockMin = equipment.StockMin;
				model.CustomerId = equipment.CustomerId;
				model.CreatedOn = equipment.CreatedOn;
				model.Published = true;

				if (equipment.Places != null && equipment.Places.Any())
				{
					model.PlaceIds = equipment.Places.Select(cr => cr.Id).ToList();
					model.PlaceNames = string.Join(",", equipment.Places.Select(x => x.Name));
				}
			}
			//categories
			PrepareAllCategoriesModel(model);
			return View(model);
		}

		public virtual ActionResult EquipmentAddPopup(int pId)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var model = new EquipmentModel
			{
				CategoryMainId = (int)CategoryMainEnum.配件
			};
			var equipment = _xJEquipmentService.GetXJEquipmentById(pId);
			if (null != equipment)
			{
				model.CategoryId = equipment.CategoryId;
				model.PId = pId;
				model.MeanLife = equipment.MeanLife;
				model.Manufacturer = equipment.Manufacturer;
				model.Specification = equipment.Specification;
				model.Unit = equipment.Unit;
				model.Published = true;
			}
			//categories
			PrepareAllCategoriesModel(model);
			return View(model);
		}

		public virtual ActionResult EquipmentEditPopup(int id)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			var model = new EquipmentModel();
			var equipment = _xJEquipmentService.GetXJEquipmentById(id);
			if (null != equipment)
			{
				model.Id = equipment.Id;
				model.CategoryMainId = equipment.CategoryMainId;
				model.CategoryId = equipment.CategoryId;
				model.PId = equipment.PId;
				model.Name = equipment.Name;
				model.Price = equipment.Price;
				model.MeanLife = equipment.MeanLife;
				model.Manufacturer = equipment.Manufacturer;
				model.Specification = equipment.Specification;
				model.Unit = equipment.Unit;
				model.DisplayOrder = equipment.DisplayOrder;
				model.StockMin = equipment.StockMin;
				model.CustomerId = equipment.CustomerId;
				model.CreatedOn = equipment.CreatedOn;
				model.Published = true;
			}
			//categories
			PrepareAllCategoriesModel(model);
			return View(model);
		}

		[HttpPost]
		[FormValueRequired("save")]
		public virtual ActionResult AddPopup(string btnId, string formId, EquipmentModel model)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			if (!model.PlaceIds.Any())
			{
				ModelState.AddModelError("PlaceIds", "请选择巡检点");
			}

			if (ModelState.IsValid)
			{
				var equipment = new XJEquipment
				{
					CategoryMainId = model.CategoryMainId,
					CategoryId = model.CategoryId,
					PId = model.PId,
					Name = model.Name,
					Manufacturer = model.Manufacturer,
					Specification = model.Specification,
					Unit = model.Unit,
					//MeanLife = model.MeanLife,
					//Price = model.Price,
					DisplayOrder = model.DisplayOrder,
					StockMin = model.StockMin,
					CustomerId = _workContext.CurrentCustomer.Id,
					CreatedOn = DateTime.Now,
					Published = model.Published,
				};
				_xJEquipmentService.InsertXJEquipment(equipment);

				var places = _xjPlaceService.GetPlacesByIds(model.PlaceIds.ToArray());
				if (places.Any())
				{
					foreach (var item in places)
					{
						equipment.Places.Add(item);
					}
					_xJEquipmentService.UpdateXJEquipment(equipment);
				}

				//activity log
				_customerActivityService.InsertActivity("AddNewEquipment", "新增设施设备：{0}", equipment.Name);

				_xJEquipmentCategoryService.SyncCategoryPlaces(equipment.CategoryId, _workContext.CurrentCustomer);

				ViewBag.RefreshPage = true;
				ViewBag.btnId = btnId;
				ViewBag.formId = formId;
			}

			//categories
			PrepareAllCategoriesModel(model);
			return View(model);
		}

		[HttpPost]
		[FormValueRequired("save")]
		public virtual ActionResult EditPopup(string btnId, string formId, EquipmentModel model)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			if (!model.PlaceIds.Any())
			{
				ModelState.AddModelError("PlaceIds", "请选择巡检点");
			}

			if (ModelState.IsValid)
			{
				var user = _workContext.CurrentCustomer;
				var equipment = _xJEquipmentService.GetXJEquipmentById(model.Id);
				if (null != equipment)
				{
					int oldCategoryId = equipment.CategoryId;
					equipment.CategoryMainId = model.CategoryMainId;
					equipment.CategoryId = model.CategoryId;
					equipment.PId = model.PId;
					equipment.Name = model.Name;
					equipment.Manufacturer = model.Manufacturer;
					equipment.Specification = model.Specification;
					equipment.Unit = model.Unit;
					//equipment.MeanLife = model.MeanLife;
					//equipment.Price = model.Price;
					equipment.DisplayOrder = model.DisplayOrder;
					equipment.StockMin = model.StockMin;
					equipment.Published = model.Published;
					var allPlaces = _xjPlaceService.GetAllPlaces(showHidden: false);
					foreach (var place in allPlaces)
					{
						if (model.PlaceIds.Contains(place.Id))
						{
							//new role
							if (equipment.Places.Count(cr => cr.Id == place.Id) == 0)
								equipment.Places.Add(place);
						}
						else
						{
							//remove role
							if (equipment.Places.Count(cr => cr.Id == place.Id) > 0)
								equipment.Places.Remove(place);
						}
					}
					_xJEquipmentService.UpdateXJEquipment(equipment);

					// 变更信息时，更新设施设备信息到使用明细中
					_xJEquipmentService.SyncInfo2Stock(equipment.Id);

					_xJEquipmentService.SyncPlacesAndCategory2Children(equipment, user);

					// 变更分类时，同步原分类
					if (oldCategoryId > 0 && equipment.CategoryId != oldCategoryId)
						_xJEquipmentCategoryService.SyncCategoryPlaces(oldCategoryId, user);

					// 同步当前分类
					_xJEquipmentCategoryService.SyncCategoryPlaces(equipment.CategoryId, user);

					//activity log
					_customerActivityService.InsertActivity("EditEquipment", "编辑设施设备：{0}", equipment.Name);

					ViewBag.RefreshPage = true;
					ViewBag.btnId = btnId;
					ViewBag.formId = formId;
				}
			}

			//categories
			PrepareAllCategoriesModel(model);
			return View(model);
		}

		[HttpPost]
		[FormValueRequired("save")]
		public virtual ActionResult EquipmentAddPopup(string btnId, string formId, EquipmentModel model)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			if (ModelState.IsValid)
			{
				if (model.Id == 0)
				{

					var equipment = new XJEquipment
					{
						CategoryMainId = model.CategoryMainId,
						CategoryId = model.CategoryId,
						PId = model.PId,
						Name = model.Name,
						Price = model.Price,
						MeanLife = model.MeanLife,
						Manufacturer = model.Manufacturer,
						Specification = model.Specification,
						Unit = model.Unit,
						DisplayOrder = model.DisplayOrder,
						StockMin = model.StockMin,
						CustomerId = _workContext.CurrentCustomer.Id,
						CreatedOn = DateTime.Now,
						Published = model.Published,
					};
					_xJEquipmentService.InsertXJEquipment(equipment);

					//activity log
					_customerActivityService.InsertActivity("AddNewEquipment", "新增设施设备：{0}", equipment.Name);
				}
				else
				{
					var equipment = _xJEquipmentService.GetXJEquipmentById(model.Id);
					if (null != equipment)
					{
						equipment.CategoryMainId = model.CategoryMainId;
						equipment.CategoryId = model.CategoryId;
						equipment.PId = model.PId;
						equipment.Name = model.Name;
						equipment.Price = model.Price;
						equipment.MeanLife = model.MeanLife;
						equipment.Manufacturer = model.Manufacturer;
						equipment.Specification = model.Specification;
						equipment.Unit = model.Unit;
						equipment.DisplayOrder = model.DisplayOrder;
						equipment.StockMin = model.StockMin;
						equipment.Published = model.Published;
						_xJEquipmentService.UpdateXJEquipment(equipment);

						//activity log
						_customerActivityService.InsertActivity("EditEquipment", "编辑设施设备：{0}", equipment.Name);
					}
				}
			}

			ViewBag.RefreshPage = true;
			ViewBag.btnId = btnId;
			ViewBag.formId = formId;
			return View(model);
		}

		[HttpPost]
		[FormValueRequired("save")]
		public virtual ActionResult EquipmentEditPopup(string btnId, string formId, EquipmentModel model)
		{
			if (!_permissionService.Authorize(StandardPermissionProvider.ManageEquipments))
				return AccessDeniedView();

			if (ModelState.IsValid)
			{
				if (model.Id == 0)
				{
					var equipment = new XJEquipment
					{
						CategoryMainId = model.CategoryMainId,
						CategoryId = model.CategoryId,
						PId = model.PId,
						Name = model.Name,
						Price = model.Price,
						MeanLife = model.MeanLife,
						Manufacturer = model.Manufacturer,
						Specification = model.Specification,
						Unit = model.Unit,
						DisplayOrder = model.DisplayOrder,
						StockMin = model.StockMin,
						CustomerId = _workContext.CurrentCustomer.Id,
						CreatedOn = DateTime.Now,
						Published = model.Published,
					};
					_xJEquipmentService.InsertXJEquipment(equipment);

					//activity log
					_customerActivityService.InsertActivity("AddNewEquipment", "新增设施设备：{0}", equipment.Name);
				}
				else
				{
					var equipment = _xJEquipmentService.GetXJEquipmentById(model.Id);
					if (null != equipment)
					{
						equipment.CategoryMainId = model.CategoryMainId;
						equipment.CategoryId = model.CategoryId;
						equipment.PId = model.PId;
						equipment.Name = model.Name;
						equipment.Price = model.Price;
						equipment.MeanLife = model.MeanLife;
						equipment.Manufacturer = model.Manufacturer;
						equipment.Specification = model.Specification;
						equipment.Unit = model.Unit;
						equipment.DisplayOrder = model.DisplayOrder;
						equipment.StockMin = model.StockMin;
						equipment.Published = model.Published;
						_xJEquipmentService.UpdateXJEquipment(equipment);

						//activity log
						_customerActivityService.InsertActivity("EditEquipment", "编辑设施设备：{0}", equipment.Name);
					}
				}
			}

			ViewBag.RefreshPage = true;
			ViewBag.btnId = btnId;
			ViewBag.formId = formId;
			return View(model);
		}

		#endregion

		[AcceptVerbs(HttpVerbs.Get)]
		public virtual ActionResult GetEquipmentsByCategoryId(string categoryId)
		{
			// This action method gets called via an ajax request
			if (String.IsNullOrEmpty(categoryId))
				throw new ArgumentNullException("categoryId");

			var result = _xJEquipmentService.GetAllEquipments(
				categoryId: Convert.ToInt32(categoryId),
				pageSize: int.MaxValue).Select(x => new { id = x.Id, name = x.Name }).ToList();
			//asterisk
			result.Insert(0, new { id = 0, name = "无" });
			return Json(result, JsonRequestBehavior.AllowGet);
		}
	}
}